package com.lzh.seatrend.util.ResourcePatternResolver;

import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;

import java.io.IOException;

/**
 * @author liuzihao
 */
public class ResourcePatternResolverLearn {

    public static void main(String[] args) throws IOException {
        ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();

//classpath: 表示加载当前类路径中所有匹配的资源
        Resource[] resources = resourcePatternResolver.getResources("classpath:spring/*.xml");
        for (Resource r : resources) {
            System.out.println(r.getFilename()); //文件名
            System.out.println(r.getURL().getPath()); //文件绝对路径
            System.out.println(r.getFile()); //File对象
            System.out.println(r.getInputStream()); //InputStream对象
        }

//classpath*: 表示加载类路径中所有匹配的资源
        resources = resourcePatternResolver.getResources("classpath*:com/cjm/**/*.class");
        for (Resource r : resources) {
            System.out.println(r.getURL().getPath()); //文件绝对路径
        }

//加载文件系统中的资源
        Resource r = resourcePatternResolver.getResource("file:c:/dd.properties");
//        System.out.println(org.apache.commons.io.IOUtils.toString(r.getInputStream())); //读取文件内容
    }

}